// 创建关系链
class Node {
  instance: any
  child: any
  sibling: any
  return: any
  constructor(instance: any) {
    this.instance = instance
    this.child = null
    this.sibling = null
    this.return = null
  }
}
function link(parent: any, children: any) {
  if (children === null)
    children = []

  // child 指向第一个子元素
  parent.child = children.reduceRight((previous: any, current: any) => {
    const node = new Node(current)
    node.return = parent
    // sibling 指向前面处理的元素
    node.sibling = previous
    return node
  }, null)

  return parent.child
}
function doWork(node: any) {
  // 创建关系链
  const children = node.type(node.props)
  return link(node, children)
}

function walk(node: any) {
  const root = node
  while (true) {
    const child = doWork(node)

    if (child) {
      node = child
      continue
    }

    if (node === root) {
      return
    }

    while (!node.sibling) {
      if (!node.return || node.return === root) {
        return
      }

      node = node.return
    }

    node = node.sibling
  }
}

// const hostNode = new Node(a1);

// const root = hostNode;
// let node = root;

export default walk
